home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / lib / c / ulog / Ulog_RecordLogout.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-01-02  |  2.4 KB  |  88 lines

  1. /* 
  2.  * ULog_RecordLogout.c --
  3.  *
  4.  *    Source code for the ULog_RecordLogout procedure.
  5.  *
  6.  * Copyright 1988 Regents of the University of California
  7.  * Permission to use, copy, modify, and distribute this
  8.  * software and its documentation for any purpose and without
  9.  * fee is hereby granted, provided that the above copyright
  10.  * notice appear in all copies.  The University of California
  11.  * makes no representations about the suitability of this
  12.  * software for any purpose.  It is provided "as is" without
  13.  * express or implied warranty.
  14.  */
  15.  
  16. #ifndef lint
  17. static char rcsid[] = "$Header: /sprite/src/lib/c/ulog/RCS/Ulog_RecordLogout.c,v 1.5 89/01/02 13:54:25 douglis Exp $ SPRITE (Berkeley)";
  18. #endif not lint
  19.  
  20.  
  21. #include <ulog.h>
  22. #include "ulogInt.h"
  23.  
  24.  
  25. /*
  26.  *----------------------------------------------------------------------
  27.  *
  28.  * Ulog_RecordLogout --
  29.  *
  30.  *    Remove information for a user from the database after the user
  31.  *     logs out.
  32.  *
  33.  *    Note: for now, this just nulls out the "user log" entry showing
  34.  *    who's logged in on a particular host/port combination.  It
  35.  *    can later be modified to update a "last" like database showing time
  36.  *    logged out as well as time logged in.
  37.  *
  38.  * Results:
  39.  *    -1 indicates an error, in which case errno indicates more details.
  40.  *    0 indicates success.
  41.  *
  42.  * Side effects:
  43.  *    The database file is updated.
  44.  *
  45.  *----------------------------------------------------------------------
  46.  */
  47.  
  48. /* ARGSUSED */
  49. int
  50. Ulog_RecordLogout(uid, portID)
  51.     int uid;        /* user identifier */
  52.     int portID;        /* index into host's area in userLog */
  53. {
  54.     int status;
  55.     char myHostName[ULOG_LOC_LENGTH];
  56.     char buffer[ULOG_RECORD_LENGTH];
  57.     Host_Entry *hostPtr;
  58.  
  59.     if (portID >= ULOG_MAX_PORTS || portID < 0) {
  60. #ifdef DEBUG
  61.     syslog(LOG_ERR, "recording logout: invalid port: %d\n", portID);
  62. #endif
  63.     errno = EINVAL;
  64.     return(-1);
  65.     }
  66.  
  67.     if (gethostname(myHostName, ULOG_LOC_LENGTH) < 0) {
  68.     syslog(LOG_ERR, "Ulog_RecordLogout: error in gethostname.\n");
  69.     return(-1);
  70.     }
  71.     hostPtr = Host_ByName(myHostName);
  72.     Host_End();
  73.     if (hostPtr == (Host_Entry *) NULL) {
  74.     syslog(LOG_ERR,
  75.            "Ulog_RecordLogout: error in Host_ByName for current host.\n");
  76.     return(-1);
  77.     }
  78.  
  79.     bzero(buffer, ULOG_RECORD_LENGTH);
  80.     (void) sprintf(buffer, ULOG_FORMAT_STRING, -1, hostPtr->id, portID,
  81.              0, "(none)");
  82.  
  83.     status = Db_WriteEntry(ULOG_FILE_NAME, buffer,
  84.                hostPtr->id * ULOG_MAX_PORTS + portID,
  85.                ULOG_RECORD_LENGTH, DB_LOCK_BREAK);
  86.     return(status);
  87. }
  88.